<?php

use Phalcon\Mvc\Model;

/**
 * 积分记录-模型
 */
class CreditRecord extends Model
{

    public $id;
    public $uid;
    public $amount;
    public $dt;
    public $reltype;
    public $relid;

    public function initialize()
    {
        $this->setSource("client_credit_record");
    }

    /**
     * 写入订单积分记录
     * @param $uid
     * @param $amount
     * @param $reltype
     * @param $relid
     */
    public static function log($uid, $amount, $reltype, $relid, $remark = '')
    {
        $record = new CreditRecord();
        $record->uid = $uid;
        $record->amount = $amount;
        $record->reltype = $reltype;
        $record->relid = $relid;
        $record->remark = $remark;
        // 记录时间
        $record->dt = date('Y-m-d H:i:s');
        try {
            return $record->save();
        } catch (Exception $ex) {
            return false;
        }
    }

}